package com.ninong.ker.admin.rest;

import com.ninong.ker.admin.service.dto.DicDTO;
import com.ninong.ker.common.tools.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ninong.ker.admin.domain.Dic;
import com.ninong.ker.admin.sevice.DicService;
import com.ninong.ker.common.annotation.log.Log;
import com.ninong.ker.common.annotation.perm.CmdAdmin;
import com.ninong.ker.common.response.CmdResponse;

/**
 * 系统字典
 * @author cmd
 *
 */
@RestController
@RequestMapping("/cmd/v1/dic")
public class DicResources {
	
	@Autowired
	private DicService dicService;
	
	@Log("字典列表")
	@CmdAdmin({"admin","dic:list"})
	@PostMapping
	public ResponseEntity<CmdResponse> list(@RequestBody DicDTO entity)  {
		CmdResponse response = new CmdResponse();
		response.setData(dicService.listPage(entity));
		return ResponseEntity.ok(response);
	}
	
	@Log("字典删除")
	@CmdAdmin({"admin","dic:delete"})
	@DeleteMapping
	public ResponseEntity<CmdResponse> delete(@RequestBody String[] ids)  {
		CmdResponse response = new CmdResponse();
		dicService.delete(ids);
		String mess = PropertyUtil.getProperty("DELETE_SUCCESS");
		response.setMessage(mess);
		return ResponseEntity.ok(response);
	}
	
	@Log("字典新增或编辑")
	@CmdAdmin({"admin","dic:add","dic:update"})
	@PutMapping
	public ResponseEntity<CmdResponse> create(@RequestBody Dic entity)  {
		dicService.create(entity);
		return ResponseEntity.ok(new CmdResponse());
	}
	
	@Log("字典详情")
	@GetMapping(value = "/{id}")
	public ResponseEntity<CmdResponse> get(@PathVariable String id)  {
		CmdResponse response = new CmdResponse();
		response.setData(dicService.get(id));
		return ResponseEntity.ok(response);
	}
}
